//
//  SellRecodeTableViewCell.m
//  EasyToTesco2.0
//
//  Created by knew on 16/11/14.
//  Copyright © 2016年 EasyToTesco. All rights reserved.
//

#import "SellRecodeTableViewCell.h"

#define CellHeight 140

#define Margin 8

#define TextFont 15


@interface SellRecodeTableViewCell ()

/**
 头部交易Label
 */
@property (nonatomic,strong)UILabel *headerLabel;

/**
 *  转入金额Label
 */
@property (nonatomic,strong)UILabel *topUpMoney;

/**
 *  编号Label
 */
@property (nonatomic,strong)UILabel *numberLabel;

/**
 *  转入电话Label
 */
@property (nonatomic,strong)UILabel *phoneLabel;


/**
 *  推广费Label
 */
@property (nonatomic,strong)UILabel *popularizeLabel;


/**
 *  时间Label
 */
@property (nonatomic,strong)UILabel *timeLabel;

/**
 备注
 */
@property (nonatomic,strong)UILabel *moreLabel;


@end

@implementation SellRecodeTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self addCooperateRecodeFirstCellUI];
        [self addCooperateRecodeSecondCellUI];
    }
    return self;
}

- (void)addCooperateRecodeFirstCellUI {
    UIView *headerView = [[UIView alloc] init];
    headerView.backgroundColor = BACKGROUND_COLOR;
    [self.contentView addSubview:headerView];
    
    [headerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left);
        make.top.equalTo(self.contentView.mas_top);
        make.width.mas_equalTo(WIDTH);
        make.height.mas_equalTo(30);
    }];
    
    UILabel *headerLabel = [[UILabel alloc] init];
    headerLabel.text = @"已发货";
    headerLabel.textColor = DEFAULT_COLOR;
    [headerView addSubview:headerLabel];
    [self.contentView addSubview:headerLabel];
    self.headerLabel = headerLabel;
    
    [headerLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).with.offset(Margin * 2);
        make.top.equalTo(headerLabel.mas_top);
        make.width.mas_equalTo(WIDTH * 0.2);
        make.height.mas_equalTo(30);
    }];
    
    UILabel *timeLabel = [[UILabel alloc] init];
    timeLabel.font = [UIFont systemFontOfSize:TextFont];
    timeLabel.textAlignment = NSTextAlignmentRight;
    self.timeLabel = timeLabel;
    self.timeLabel.text = @"商品名称:竹炭花生";
    [self.contentView addSubview:timeLabel];
    
    [timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView.mas_right).with.offset(-Margin * 2);
        make.top.equalTo(headerLabel.mas_top);
        make.left.equalTo(headerLabel.mas_right);
        make.height.mas_equalTo(30);
    }];
}

- (void)addCooperateRecodeSecondCellUI {
    UILabel *numberLabel = [[UILabel alloc] init];
    numberLabel.text = @"订单号: 2918090";
    numberLabel.font = [UIFont systemFontOfSize:TextFont];
    numberLabel.textAlignment = NSTextAlignmentLeft;
    self.numberLabel = numberLabel;
    [self.contentView addSubview:numberLabel];
    
    [numberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).with.offset(Margin * 2);
        make.top.equalTo(self.headerLabel.mas_bottom);
        
        //        if(iPhone5) {
        make.width.mas_equalTo(WIDTH * 0.6);
        //        } else {
        //            make.width.mas_equalTo(WIDTH * 0.3);
        //        }
        
        make.height.mas_equalTo(30);
    }];
    
    UILabel *phoneLabel = [[UILabel alloc] init];
    phoneLabel.text = @"18620614920";
    phoneLabel.font = [UIFont systemFontOfSize:TextFont];
    phoneLabel.textAlignment = NSTextAlignmentRight;
    self.phoneLabel = phoneLabel;
    [self.contentView addSubview:phoneLabel];
    
    [phoneLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        if(iPhone5) {
            make.width.mas_equalTo(WIDTH * 0.4 + Margin * 4);
        } else {
            make.width.mas_equalTo(WIDTH * 0.4 + Margin * 2);
        }
        make.right.equalTo(self.contentView.mas_right).with.offset(-Margin * 2);
        make.top.equalTo(self.headerLabel.mas_bottom);
        make.height.mas_equalTo(30);
    }];
    
    UILabel *topUpMoney = [[UILabel alloc] init];
    topUpMoney.text = @"金额: ¥389008";
    topUpMoney.textAlignment = NSTextAlignmentLeft;
    topUpMoney.font = [UIFont systemFontOfSize:TextFont];
    self.topUpMoney = topUpMoney;
    [self.contentView addSubview:topUpMoney];
    
    [topUpMoney mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).with.offset(Margin * 2);
        make.top.equalTo(numberLabel.mas_bottom);
        make.width.mas_equalTo(WIDTH * 0.3);
        make.height.mas_equalTo(30);
    }];
    
    UILabel *popularizeLabel = [[UILabel alloc] init];
    popularizeLabel.text = @"下单时间: 2016-11-14 16:21";
    popularizeLabel.textAlignment = NSTextAlignmentRight;
    popularizeLabel.font = [UIFont systemFontOfSize:TextFont];
    self.popularizeLabel = popularizeLabel;
    [self.contentView addSubview:popularizeLabel];
    
    [popularizeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView.mas_right).with.offset(-Margin * 2);
        make.top.equalTo(phoneLabel.mas_bottom);
        make.width.mas_equalTo(WIDTH * 0.7);
        make.height.mas_equalTo(30);
    }];
    
    UILabel *moreLabel = [[UILabel alloc] init];
    moreLabel.text = @"备注:";
    moreLabel.font = [UIFont systemFontOfSize:TextFont];
    self.moreLabel = moreLabel;
    [self.contentView addSubview:moreLabel];
    
    [moreLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).offset(Margin * 2);
        make.top.equalTo(topUpMoney.mas_bottom);
        make.width.mas_equalTo(WIDTH * 0.7);
        make.height.mas_equalTo(30);
    }];
    
    UIButton *pushButton = [UIButton buttonWithType:UIButtonTypeSystem];
    [pushButton setTitle:@"查看详情" forState:UIControlStateNormal];
    [pushButton setTitleEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 10)];
    pushButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    pushButton.titleLabel.font = [UIFont systemFontOfSize:TextFont];
    [self.contentView addSubview:pushButton];
    self.pushButton = pushButton;
    
    [pushButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView.mas_right).with.offset(-Margin * 2);
        make.top.equalTo(popularizeLabel.mas_bottom);
        make.width.mas_equalTo(WIDTH * 0.3);
        make.height.mas_equalTo(30);
    }];
}

- (void)setRecodeModel:(SellRecodeModel *)recodeModel {
    _recodeModel = recodeModel;
    
    if ([recodeModel.kuaidi isEqualToString:@"1"]) {
        self.headerLabel.text = @"已发货";
    } else if ([recodeModel.kuaidi isEqualToString:@"4"]) {
        self.headerLabel.text = @"已收货";
    } else {
        self.headerLabel.text = @"未发货";
    }
    
    self.topUpMoney.text = [NSString stringWithFormat:@"金额: %@",recodeModel.zongjia];
    self.numberLabel.text = [NSString stringWithFormat:@"订单号: %@",recodeModel.dxh];
    self.phoneLabel.text = [NSString stringWithFormat:@"%@",recodeModel.username];
    self.popularizeLabel.text = [NSString stringWithFormat:@"下单时间: %@",recodeModel.addtime];
    self.timeLabel.text = [NSString stringWithFormat:@"商品名称: %@",recodeModel.shopname];
    self.moreLabel.text = [NSString stringWithFormat:@"备注: %@",recodeModel.remark];
}

@end
